import 'package:common/common.dart';

/// 自定义主题色按钮
class AppPrimaryButton extends StatefulWidget {
  final Widget? child;
  final double? width;
  final double? height;
  final EdgeInsets? padding;
  final EdgeInsets? margin;
  final Function()? onTap;

  const AppPrimaryButton({Key? key, this.child, this.width, this.height, this.padding, this.margin, this.onTap}) : super(key: key);

  @override
  State<AppPrimaryButton> createState() => _AppPrimaryButtonState();
}

class _AppPrimaryButtonState extends State<AppPrimaryButton> {
  bool pressed = false;

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
        onTapDown: (value) => setState(() => pressed = true),
        onTapUp: (value) => setState(() => pressed = false),
        onTapCancel: () => setState(() => pressed = false),
        onTap: widget.onTap,
        child: AnimatedContainer(
            duration: const Duration(milliseconds: 150),
            width: widget.width,
            height: widget.height,
            padding: widget.padding,
            margin: widget.margin,
            decoration: BoxDecoration(
                color: pressed ? AppColor.primary.withOpacity(0.3) : AppColor.primary,
                borderRadius: BorderRadius.circular(4.0),
                boxShadow: [BoxShadow(color: AppColor.gray[100]!, blurRadius: 10.0)]),
            alignment: Alignment.center,
            child: widget.child));
  }
}
